/*
 * @Author: xiaosihan 
 * @Date: 2024-08-20 15:43:42 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-02 19:14:35
 */

import { Object3D } from "three";
import { GLTFExporter } from "three/examples/jsm/Addons.js";
//@ts-ignore
// import GLTFExporter from "./GLTFExporter.es.js";
const gltfExporter = new GLTFExporter();

// 导出模型
export default function exportGlb(Object3d: Object3D) {
    return new Promise<ArrayBuffer>(async (resolve, reject) => {
        const glbArrayBuffer = await gltfExporter.parseAsync(Object3d, {
            trs: true,
            onlyVisible: true,
            truncateDrawRange: true,
            binary: true,
            embedImages: true,
            maxTextureSize: 1024,
            animations: Object3d.animations,
            forceIndices: false, // 为几何体生成索引
            includeCustomExtensions: false
        });

        resolve(glbArrayBuffer as ArrayBuffer);
    });
}